#include "example.srpc.h"
#include "workflow/WFFacilities.h"

using namespace srpc;


static void echo_callback(EchoResponse *response, srpc::RPCContext *context)
{
    // 判断远程过程调用是否成功
    if (context->success()) {
        std::cout << "Response: { message=" << response->message() << " }\n";
    } else {
        std::cout << "status code: " << context->get_status_code()
            << ", error: " << context->get_error()
            << ", errmsg: " << context->get_errmsg() << "\n";
    }
}

int main()
{
	const char *ip = "127.0.0.1";
	unsigned short port = 9527;
    // 创建SRPC的客户端
	Example::SRPCClient client{ ip, port };

    // 设置请求参数
	EchoRequest req;
    req.set_message("Hello, SRPC!\n");
    req.set_name("xixi");
    
    // 2. 调用远程方法 (和调用本地方法的形式是一样的)
    EchoResponse resp; 
    RPCSyncContext ctx;
    client.Echo(&req, &resp, &ctx); /* 同步调用 */

    if (ctx.success) {
        std::cout << "Response: { message=" << resp.message() << " }\n";
    } else {
        std::cerr << "status code: " << ctx.status_code 
            << ", error: " << ctx.error
            << ", errmsg: " << ctx.errmsg << "\n";
    }

    std::cout << "after Echo()\n";
    getchar();
	return 0;
}
